#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    // int n=s.size();
    if(s[0]=='1'&&s[1]=='0'||s[n-1]=='1')
    {
        cout<<"NO"<<endl;
        return;
    }
    for(int i=1;i<=2;i++)
    {
        if(s[i]=='1')
        {
            if(s[i+1]=='0'&&s[i-1]=='0')
            {
                cout<<"NO"<<endl;
                return;
            }
        }
    }
    for(int i=3;i<n-1;i++)
    {
        if(s[i]=='1')
        {
            if(s[i+1]=='0'&&s[i-1]=='0')
            {
                int cnt=0;
                for(int j=i-2;j>=0;j--)
                {
                    if(s[j]=='1')cnt++;
                }
                if(cnt<2)
                {
                    cout<<"NO"<<endl;
                    return;
                }
            }
        }
    }
    cout<<"YES"<<endl;
}
signed main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    int T=1;
    cin>>T;
    while(T--)
    {
       solve();
    }
    return 0;
}